﻿using ConfExpert.Forms.Siparisler;
using ConfExpert.Utility;
using DevExpress.XtraEditors;
using DevTeam;
using System;
using System.Windows.Forms;

namespace ConfExpert.Forms.Depo
{
    public partial class StokKartiDuzelt : XPopupForm
    {
        public StokKartiDuzelt()
        {
            InitializeComponent();
        }

        private void StokKartiDuzelt_Load(object sender, EventArgs e)
        {
            if (ytk(143))
                btnEkle.Enabled = btnSil.Enabled = btnDegistir.Enabled = false;

            gle1.Properties.Assign(RI(Rp.V_Kumas));
            sle2.Properties.Assign(RI(Rp.V_Kumas));
            sle3a.Properties.Assign(RI(Rp.V_Kumas));
            sle3b.Properties.Assign(RI(Rp.V_Kumas));

            btnDegistir.Click += new EventHandler(btnDegistir_Click);
            btnSil.Click += new EventHandler(btnSil_Click);
            gle1.DoubleClick += new EventHandler(gle_DoubleClick);
            sle2.DoubleClick += new EventHandler(gle_DoubleClick);
            sle3a.DoubleClick += new EventHandler(gle_DoubleClick);
            sle3b.DoubleClick += new EventHandler(gle_DoubleClick);
            btnBirlestir.Click += new EventHandler(btnBirlestir_Click);

            btnEkle.Click += new EventHandler(btnEkle_Click);
        }

        //void btnChange_Click(object sender, EventArgs e)
        //{
        //    if (intParse(gleYeniProductId.EditValue) > 0)
        //        if (intParse(txtRollId.Text) > 0)
        //            if (intParse(ExecScalar("KartChange2", intParse(txtRollId.Text), intParse(gleYeniProductId.EditValue), WhoAmI)) > 0)
        //                XtraMessageBox.Show("Topun ProductId'si değiştirildi.");
        //}

        void btnEkle_Click(object sender, EventArgs e)
        {
            if (intParse(ExecuteScalar("KartAc", teDN.Text, WhoAmI)) > 0)
            {
                AppSession.MainForm.RefreshData();
                XtraMessageBox.Show("Kart açıldı.");
            }
        }

        void btnBirlestir_Click(object sender, EventArgs e)
        {
            if (intParse(sle3a.EditValue) > 0 && intParse(sle3b.EditValue) > 0)
                if (XtraMessageBox.Show("Emin misiniz?", "Confirmation", MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes)
                {
                    ExecuteNonQuery("KartBirlestir", intParse(sle3a.EditValue), intParse(sle3b.EditValue));
                    AppSession.MainForm.RefreshData();
                    XtraMessageBox.Show("Kartlar birleştirildi.");
                }
        }

        void gle_DoubleClick(object sender, EventArgs e)
        {
            GridLookUpEdit gle = sender as GridLookUpEdit;
            using (FuzzySearch fs = new FuzzySearch())
            {
                if (fs.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                    gle.EditValue = fs.ProductId;
            }
        }

        void btnSil_Click(object sender, EventArgs e)
        {
            if (intParse(gle1.EditValue) > 0)
                if (XtraMessageBox.Show("Emin misiniz?", "Confirmation", MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes)
                {
                    ExecuteNonQuery("KartSil", intParse(gle1.EditValue));
                    AppSession.MainForm.RefreshData();
                    XtraMessageBox.Show("Kart silindi.");
                }
        }

        void btnDegistir_Click(object sender, EventArgs e)
        {
            if (intParse(sle2.EditValue) > 0 && te2DN.Text.Trim() != string.Empty)
                if (XtraMessageBox.Show("Emin misiniz?", "Confirmation", MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes)
                {
                    ExecuteNonQuery("KartSKDegistir", intParse(sle2.EditValue), te2DN.Text.Trim(), WhoAmI);
                    AppSession.MainForm.RefreshData();
                    XtraMessageBox.Show("Kart değiştirildi.");
                }
        }
    }
}